#include "widget.h"
#include "ui_widget.h"
#include<QThread>
#include<QTimer>
#include<QTime>
#include<stdlib.h>
#include<QVBoxLayout>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->widget->resize(500,550);

    diaPlot= new DialPlot(ui->widget);
    diaPlot->resize(500,500);

    QVBoxLayout * vLayout = new QVBoxLayout;
    vLayout->addWidget(diaPlot);
    vLayout->addWidget(ui->pushButton);
    vLayout->addWidget(ui->horizontalSlider);
    setLayout(vLayout);

    timer = new QTimer();
    connect(timer, &QTimer::timeout, this, &Widget::timeUpdate);
    qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
}


// widget的绘制事件
void Widget::paintEvent(QPaintEvent *)
{
    int side =qMin(width(),height());
    ui->widget->setGeometry((width()-side)/2,(height()-side)/2,side,side);
}

void Widget::on_pushButton_clicked()
{
    timer->start(1000);
}

// 定时更新
void Widget::timeUpdate()
{
    int rand = qrand()%100;
    diaPlot->testChangValue(rand);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_horizontalSlider_valueChanged(int value)
{
    timer->stop();
    diaPlot->testChangValue(value);
}
